package net.nshc.kwkim.mycalc.temp;

public class StackOfInts {
	public StackOfInts()
	{
		countF = 0;
		arrayF = new int[INITIAL_CAPACITY];
	}

	public void push(int newItem)
	{
		if (countF == arrayF.length) {
			int[] oldArray = arrayF;
			arrayF = new int[2 * oldArray.length];
			for (int i = 0; i < oldArray.length; i++)
				arrayF[i] = oldArray[i];
		}
		arrayF[countF] = newItem;
		countF++;
	}

	public void pop()
	{
		countF--;
		if (countF == arrayF.length / 4 && arrayF.length > INITIAL_CAPACITY) {
			int[] oldArray = arrayF;
			arrayF = new int[oldArray.length / 2];
			for (int i = 0; i < countF; i++)
				arrayF[i] = oldArray[i];
		}
	}

	public int top()
	{
		return arrayF[countF - 1];
	}

	public boolean isEmpty()
	{
		return countF == 0;
	}

	private int[] arrayF;
	private int countF;
	private static final int INITIAL_CAPACITY = 4;
}
